import javax.swing.*;
import javax.swing.text.html.ImageView;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class Menu {
    public static void showMainMenu() {
        JFrame frame = Main.getMainFrame();
        frame.setTitle("迷宫闯关游戏");

        // 创建主面板
        JPanel mainPanel = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.anchor = GridBagConstraints.CENTER;


        // 添加游戏标题
        JLabel title = new JLabel("迷宫闯关游戏");
        title.setFont(new Font("SimHei", Font.BOLD, 40));
        gbc.gridy = 0;
        gbc.weighty = 1;
        gbc.insets = new Insets(140, 0, 0, 0);
        mainPanel.add(title, gbc);

        // 创建中央面板
        JPanel centerPanel = new JPanel();
        centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
        centerPanel.setBorder(BorderFactory.createEmptyBorder(30, 0, 0, 0));

        // 进入游戏按钮
        JButton startButton = new JButton("进入游戏");
        startButton.setFont(new Font("SimHei", Font.PLAIN, 20));
        startButton.setPreferredSize(new Dimension(200, 60));
        startButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                LoginRegister.showLoginRegister();
            }
        });
        gbc.gridy = 1;
        gbc.weighty = 50;
        gbc.insets = new Insets(0, 0, 50, 0);
        mainPanel.add(startButton, gbc);

        ImageIcon imageIcon = new ImageIcon("./img/主界面图片.png");

        // 可选：调整图片大小（若需要）
        Image image = imageIcon.getImage();
        Image scaledImage = image.getScaledInstance(800, 600, Image.SCALE_SMOOTH); // 缩放为 200x200
        imageIcon = new ImageIcon(scaledImage);

        // 创建 JLabel 用于显示图片
        JLabel label = new JLabel(imageIcon);

        // 将 JLabel 添加到窗口
        frame.getContentPane().add(label);

        // 显示窗口
        frame.setVisible(true);

        frame.getContentPane().removeAll();
        frame.getContentPane().add(mainPanel);
        frame.revalidate();
        frame.repaint();
    }
}